const TokenKey = "token";
const NameKey = "userinfo";
const Type = "usertype";
const GoodsName = "goodsname";
const Flag = "flag";
const GoodsTesting = "goodstesting";

export function getToken() {
  // 根据key获取内容 如果没有当前内容 返回 null 不然返回 对象(反序列化)
  var rsObj = window.localStorage.getItem(TokenKey);
  if (!rsObj || rsObj == "undefined") {
    return null;
  } else {
    return JSON.parse(rsObj);
  }
}
export function getUser() {
  var rsObj = window.localStorage.getItem(NameKey);
  if (!rsObj || rsObj == "undefined") {
    return null;
  } else {
    return JSON.parse(rsObj);
  }
}
export function getUserType() {
  var rsObj = window.localStorage.getItem(Type);
  if (!rsObj || rsObj == "undefined") {
    return null;
  } else {
    return JSON.parse(rsObj);
  }
}
export function getGoodsName() {
  var rsObj = window.localStorage.getItem(GoodsName);
  if (!rsObj || rsObj == "undefined") {
    return null;
  } else {
    return JSON.parse(rsObj);
  }
}
export function getflag() {
  var rsObj = window.localStorage.getItem(Flag);
  if (!rsObj || rsObj == "undefined") {
    return null;
  } else {
    return JSON.parse(rsObj);
  }
}
export function getGoodsTesting() {
  var rsObj = window.localStorage.getItem(GoodsTesting);
  if (!rsObj || rsObj == "undefined") {
    return null;
  } else {
    return JSON.parse(rsObj);
  }
}

export function setGoodsTesting(testing) {
  var testingStr = JSON.stringify(testing);
  window.localStorage.setItem(GoodsTesting, testingStr);
}

export function setflag(flag) {
  var flagStr = JSON.stringify(flag);
  window.localStorage.setItem(Flag, flagStr);
}

export function setGoodsName(goodsname) {
  var goodsStr = JSON.stringify(goodsname);
  window.localStorage.setItem(GoodsName, goodsStr);
}
export function setUserType(usertype) {
  var userStr = JSON.stringify(usertype);
  window.localStorage.setItem(Type, userStr);
}
export function setUserinfo(name) {
  var userStr = JSON.stringify(name);
  window.localStorage.setItem(NameKey, userStr);
}
export function setToken(token) {
  var tokenStr = JSON.stringify(token);
  //只能存储字符串 [Object]
  window.localStorage.setItem(TokenKey, tokenStr);
}

export function removeToken() {
  return window.localStorage.clear();
}
export function removeGoodsName() {
  return window.localStorage.removeItem(GoodsName);
}
export function removeflag() {
  return window.localStorage.removeItem(Flag);
}
export function removeGoodsTesting() {
  return window.localStorage.removeItem(GoodsTesting);
}
